package service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.BaseMapper;
import com.common.BaseService;

import beans.sys.UserBean;
import beans.user.UserSearch;
import beans.user.user;
import beans.wxresult.Rec;
import mapper.user.wxuserMapper;

@Service
@Transactional
public class WXUserServiceImpl<T> extends BaseService<T>{

	@Autowired
	private wxuserMapper<T> _userMapper;

	@Override
	public BaseMapper<T> getMapper() {
		return _userMapper;
	}

	public void updateSubscribe(String openid, String status) {
		_userMapper.updateSubscribe(openid,status);
	}

	/**
	 * 获取推荐人
	 * @param openid
	 */
	public T getSceenstr(String openid) {
		return _userMapper.getSceenstr(openid);
	}
	
	/**
	 * 更新推荐金额
	 * @param openid
	 * @param money
	 */
	public void updateMoney(String openid,Double money) {
		_userMapper.updateMoney(openid, money);
	}

	/**
	 * 获取所有分享的人
	 * @param openid
	 * @return
	 */
	public List<T> getSecUser(String openid) {
		return _userMapper.getSecUser(openid);
	}

	public void updateCurrentMoney(String openid, Double currentmoney) {
		_userMapper.updateCurrentMoney(openid,currentmoney);
	}

	public List<T> queryByIds(String[] ids) {
		return _userMapper.queryByIds(ids);
	}

	/**
	 * 批量添加题目
	 * @param mapList
	 */
	public void adds(List<T> mapList) {
		_userMapper.adds(mapList);
	}

	/**
	 * 获取没有代理账号的会员
	 * @return
	 */
	public List<T> getAll() {
		return _userMapper.getAll();
	}

	/**
	 * 
	 * @param ids
	 * @return
	 */
	public List<T> getByIds(String[] ids) {
		return _userMapper.queryByIds(ids);
	}

	/**
	 * 获取代理的会员
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	public List<T> queryAgentUserByList(UserSearch model) throws Exception {
		Integer rowCount = _userMapper.queryAgentUserByCount(model);
		model.getPager().setRowCount(rowCount);
		model.setPage((model.getPage()-1)*model.getRows());

		Double d = rowCount.doubleValue()/model.getRows().doubleValue();
		model.getPager().setPageCount((int)Math.ceil(d));
		return _userMapper.queryAgentUserByList(model);
	}
}